import subCard from './subCard.module.scss'
import React, { Component } from 'react';
import frime from '../../static/ffrime.png'
import right from '../../static/right.png'
import zn from '../../static/zinvka.png'
import qn from '../../static/qinglvka.png'
import { getSubKindList } from '../../utils/interface'
import { getUrlParam } from '../../utils/tools'
import { withRouter } from 'react-router-dom'
class SubCard extends Component {
    constructor(props) {
        super(props);
        this.state = {
            result: []
        }
    }
    render() {
        const img = function(i){
            if(i==0){
                return (<img src={frime}></img>)
            }
            if(i==1){
                return (<img src={qn}></img>)
            }
            if(i==2){
                return (<img src={zn}></img>)
            }
        }
        const item = this.state.result.map((item,index)=>{
            return (
                <div key={index} onClick={item.count<=0?'':this.go_gift.bind(this,item.id,item.NAME)} className={subCard['sub-item']}>
                    <div>
                  
                        {img(index)}
                        <div>
                            <p>{item.NAME}</p>
                            <span>可赠与{item.count}张</span>
                        </div>
                    </div>
                    <img src={right}></img>
                </div>
            )
        })
        return (
            <div className={subCard['sub-card']}>
                {item}
            </div>
        );
    }
    componentDidMount() {
        document.title = "赠送亲属卡"
        this.getCardList()
    }
    go_gift(id,name){
        this.props.history.push('/gift?type='+id+'&cardId='+getUrlParam('cardId')+'&phone='+getUrlParam('phone'))
    }
    getCardList(){
        getSubKindList({ mainCardId: getUrlParam('cardId') }).then(res => {
            this.setState({
                result: res.data.result
            })
        })
    }
    componentWillUnmount() {
        
        this.setState = (state, callback) => {
          return;
        };
      }
}
export default withRouter(SubCard)